package com.wn.main.ui

import android.annotation.SuppressLint
import androidx.lifecycle.lifecycleScope
import com.wn.common.provider.MainServiceProvider
import com.wn.framework.base.BaseActivity
import com.wn.framework.ext.countDownCoroutines
import com.wn.framework.ext.onClick
import com.wn.main.R
import com.wn.main.databinding.ActivitySplashBinding

/**
 * @Author: wn
 * @Date: 2024/8/20 15:55
 * @Description: 启动页
 */
@SuppressLint("CustomSplashScreen")
//@AndroidEntryPoint
class SplashActivity : BaseActivity<ActivitySplashBinding>() {

  override fun getLayoutRes() = R.layout.activity_splash

  override fun initView() {
    super.initView()
    mBinding.tvSkip.apply {
      // 点击跳转主页面
      onClick {
        toMainActivity()
      }
      /**
       * 倒计时  显示 3,2,1跳 主页面
       */
      countDownCoroutines(3, lifecycleScope, {
        text = getString(com.wn.framework.R.string.splash_time, it.toString())
      }) {
        toMainActivity()
      }
    }
  }

  /**
   * 跳转主页面 结束当前页面
   */
  private fun toMainActivity() {
    MainServiceProvider.toMain(this)
    finish()
  }
}